package ar.com.photo_admin.domain
import grails.plugins.springsecurity.Secured

@Secured(["isAuthenticated()"])
class NotificationController {

	def springSecurityService

	def index() { 
		redirect(action: "list")
	}
	
	def list() {
		User user = springSecurityService.getCurrentUser()
					
		params.max = Math.min(params.max ? params.int('max') : 10, 100)											
								
		user.userNotifications.each {
			it.notified = true
			it.save(flush:true)
		}
		
		def notificationsList = Notification.executeQuery(
			"select n from Notification n inner join n.userNotifications un where un.notifiedUser.id = :idNotif order by n.id desc",
			[idNotif: user.id], params)
		
		render(view: "list", model: [notificationsList: notificationsList, total: user.userNotifications.size()])				
	}	
}
